package com.fireline.beauty.cashier;

import java.math.BigDecimal;
import java.text.DecimalFormat;

import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;

import com.zgw.fireline.base.dataset.Dataset;
import com.zgw.fireline.base.widgets.ControlUtil;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

public class CzkfkDialog extends Dialog {

	protected int result;
	protected Shell shell;
	private Text text_1;
	private Text text_2;
	private Text text;
	private String xfje;
	private String knje;

	/**
	 * Create the dialog.
	 * 
	 * @param parent
	 * @param style
	 */
	public CzkfkDialog(Shell parent, String xfje, String knje) {
		super(parent, SWT.NONE);
		this.xfje = xfje;
		this.knje = knje;
	}

	/**
	 * Open the dialog.
	 * 
	 * @return the result SWT.OK | SWT.CANCEL
	 */
	public int open() {
		createContents();
		ControlUtil.centerShell(shell);
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	private final static DecimalFormat foramt = new DecimalFormat(".00");

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		shell.addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e) {
				System.out.println(e.keyCode);
			}
		});
		shell.setSize(414, 258);
		shell.setText("储值卡结账");
		shell.setLayout(new GridLayout(1, false));

		Composite composite = new Composite(shell, SWT.NONE);
		GridData gd_composite = new GridData(SWT.FILL, SWT.FILL, true, false,
				1, 1);
		gd_composite.widthHint = 402;
		composite.setLayoutData(gd_composite);
		GridLayout gl_composite = new GridLayout(3, false);
		gl_composite.verticalSpacing = 20;
		gl_composite.marginWidth = 30;
		gl_composite.marginHeight = 20;
		composite.setLayout(gl_composite);

		Label label = new Label(composite, SWT.NONE);
		label.setFont(SWTResourceManager.getFont("宋体", 14, SWT.BOLD));
		label.setText("本次消费共");

		text = new Text(composite, SWT.READ_ONLY);
		text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1,
				1));
		text.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		text.setFont(SWTResourceManager.getFont("宋体", 14, SWT.BOLD));
		text.setText(foramt.format(new Double(xfje)));
		ControlUtil.setEnterToFocusMove(text);
		Label label_1 = new Label(composite, SWT.NONE);
		label_1.setFont(SWTResourceManager.getFont("宋体", 14, SWT.BOLD));
		label_1.setText("元");

		Label label_2 = new Label(composite, SWT.NONE);
		label_2.setFont(SWTResourceManager.getFont("宋体", 14, SWT.BOLD));
		label_2.setText("储值卡内剩佘金额为");

		text_1 = new Text(composite, SWT.READ_ONLY);
		text_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false,
				1, 1));
		text_1.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		text_1.setFont(SWTResourceManager.getFont("宋体", 14, SWT.BOLD));
		text_1.setText(foramt.format(new Double(knje)));
		ControlUtil.setEnterToFocusMove(text_1);
		Label label_3 = new Label(composite, SWT.NONE);
		label_3.setFont(SWTResourceManager.getFont("宋体", 14, SWT.BOLD));
		label_3.setText("元");

		Label label_4 = new Label(composite, SWT.NONE);
		label_4.setFont(SWTResourceManager.getFont("宋体", 14, SWT.BOLD));
		label_4.setText("扣除本次消费后剩佘金额为");

		text_2 = new Text(composite, SWT.READ_ONLY);
		text_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false,
				1, 1));
		text_2.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		text_2.setFont(SWTResourceManager.getFont("宋体", 14, SWT.BOLD));
		text_2.setText(foramt.format(new BigDecimal(knje)
				.subtract(new BigDecimal(xfje))));
		ControlUtil.setEnterToFocusMove(text_2);
		Label label_5 = new Label(composite, SWT.NONE);
		label_5.setFont(SWTResourceManager.getFont("宋体", 14, SWT.BOLD));
		label_5.setText("元");

		Label lblNewLabel = new Label(shell, SWT.NONE);
		GridData gd_lblNewLabel = new GridData(SWT.LEFT, SWT.CENTER, false,
				false, 1, 1);
		gd_lblNewLabel.horizontalIndent = 30;
		lblNewLabel.setLayoutData(gd_lblNewLabel);
		lblNewLabel.setFont(SWTResourceManager.getFont("宋体", 11, SWT.NORMAL));
		lblNewLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		lblNewLabel.setText("提示：按确定直接从卡内扣除金额");

		Label label_6 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
		GridData gd_label_6 = new GridData(SWT.FILL, SWT.CENTER, false, false,
				1, 1);
		gd_label_6.verticalIndent = 10;
		label_6.setLayoutData(gd_label_6);

		Composite composite_1 = new Composite(shell, SWT.NONE);
		composite_1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true,
				true, 1, 1));
		composite_1.setLayout(new GridLayout(2, false));
		composite_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));

		Button btnNewButton_1 = new Button(composite_1, SWT.NONE);
		btnNewButton_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				result = SWT.OK;
				shell.close();
			}
		});
		btnNewButton_1.setFocus();
		btnNewButton_1
				.setFont(SWTResourceManager.getFont("宋体", 10, SWT.NORMAL));
		GridData gd_btnNewButton_1 = new GridData(SWT.LEFT, SWT.CENTER, false,
				false, 1, 1);
		gd_btnNewButton_1.heightHint = 25;
		gd_btnNewButton_1.widthHint = 80;
		btnNewButton_1.setLayoutData(gd_btnNewButton_1);
		btnNewButton_1.setText("确定（F5）");
		Button btnNewButton = new Button(composite_1, SWT.NONE);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				result = SWT.CANCEL;
				shell.close();
			}
		});
		btnNewButton.setFont(SWTResourceManager.getFont("宋体", 10, SWT.NORMAL));
		GridData gd_btnNewButton = new GridData(SWT.LEFT, SWT.CENTER, false,
				false, 1, 1);
		gd_btnNewButton.heightHint = 25;
		gd_btnNewButton.widthHint = 80;
		btnNewButton.setLayoutData(gd_btnNewButton);
		btnNewButton.setText("取消（ESC）");

	}

	public static void main(String[] args) {
		CzkfkDialog fk = new CzkfkDialog(new Shell(), "45", "100");
		fk.open();
	}
}
